<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker();
$worker->onWorkerStart = function(){
    $clientId = $clientId = rand(0, 100000) . time();
    $options = [
        'username' => 'xiaoyuansuo',
        'password' => 'zhi@nengSUO888',
        'keepalive' => true,
        'clean_session' => 30,
        'client_id' => $clientId,
    ];
    $mqtt = new Workerman\Mqtt\Client('mqtt://127.0.0.1:61613',$options);
    $mqtt->onConnect = function($mqtt) {
        $res = json_encode([
            'operator'=>'Unlock',
            'messageId'=>1111,
            'info'=>[
                'uid'=>'00021',
                'openDoor'=>'1',
                'showInfo'=>'请走开',
            ]
        ],JSON_UNESCAPED_UNICODE);
        $mqtt->publish('mqtt/face/1776817', $res);
    };
    $mqtt->connect();
};
Worker::runAll();